package org.bing.engine.common.message;

import java.util.ArrayList;
import java.util.List;

public class RouterImpl implements Router {
    private List<Filter> filters;
    private Handler handler;

    public void setFilters(List<Filter> filters) {
        this.filters = filters;
    }

    public void setHandler(Handler handler) {
        this.handler = handler;
    }

    public void init() {
        if (filters == null) {
            filters = new ArrayList<Filter>();
        }
        if (handler == null) {
            handler = new HandlerAdapter();
        }
    }

    public Message route(Message msgIn) {
        for (Filter filter : filters) {
            filter.doFilter(msgIn);
        }
        return handler.handle(msgIn);

    }
}
